from win32com.client import constants

import win32com.client as win32

from ..models.inline_shapes import InlineShapeInfo, ShapeTypes


def extract_inline_shape_info(inline_shape: "InlineShape") -> InlineShapeInfo:
    """
    Inlineshape doc: https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.office.interop.word.inlineshape?view=word-pia
    """

    # 如果类型为行内图片
    if inline_shape.Type == constants.wdInlineShapePicture:
        # 判据：如果图片在第二页的第一行，而前一页面的最后一个文字离页面底端还有较多的距离，就要报错
        # page_num = inline_shape.Range.Information(3)
        # print(
        #     page_num,
        #     inline_shape.Range.Information(constants.wdFirstCharacterLineNumber),
        # )
        # last_char = inline_shape.Range.Characters.Last
        # print(last_char.Information(6) / 28.35)  # 获取和页面上边的距离
        return InlineShapeInfo(
            type=ShapeTypes.picture,
            width=inline_shape.Width,
            height=inline_shape.Height,
        )
    else:
        return InlineShapeInfo(type=ShapeTypes.unknown)
